﻿new Vue({
    el: "#app",
    data: {
        model: {
            Name: "",
            Description: "",
        },
        validation: {
            required: [
                'Name',
                'Description',
            ]
        }
    },
    methods: {
        submit() {
            let _this = this;
            let validResult = _this.$refs.form.valid();
            if (!validResult.result) {
                return;
            }
            if (_this.model.ParentId == null) {
                _this.model.ParentId = 0;
            }

            var url = "SysRole/insert";
            if (_this.model.ID > 0) {
                url = "SysRole/update";
            }
            $http.insertOrUpdate(url, _this.model);
        },
        loadModelData() {
            var id = this.model.ID;
            if (id <= 0) {
                return;
            }
            var _this = this;
            $http.post("SysRole/singleData", { ID: id }, function (data) {
                _this.model = data;
            })
        }
    },
    mounted() {
        var id = this.$url.query("id");
        if (id != "") {
            this.model.ID = id;
        }
        this.loadModelData();
    },
})